﻿<%@ Page Language="VB" AutoEventWireup="false" CodeFile="NPLTarget.aspx.vb" Inherits="NPLTarget" MasterPageFile="~/MasterPage.master" %>


<%@ Register Assembly="ISNet.WebUI.WebTreeView" Namespace="ISNet.WebUI.WebTreeView" TagPrefix="ISWebTreeView" %>

<%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %>

<%@ Register Assembly="ISNet.WebUI.WebCombo" Namespace="ISNet.WebUI.WebCombo" TagPrefix="ISWebCombo" %>

<%@ Register Assembly="ISNet.WebUI.WebDesktop" Namespace="ISNet.WebUI.WebDesktop" TagPrefix="ISWebDesktop" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <link href="js/magicsuggest-1.2.6.css" rel="stylesheet" />
    <script src="js/magicsuggest-1.2.6.js"></script>
    <script src="script/packed.js"></script>
    <script src="script/tinybox.js"></script>
    <link href="script/style.css" rel="stylesheet" />
    <script type="text/javascript" src="js/JSON.js"></script>
    <script type="text/javascript">
        function openJS() { alert('loaded') }
        function closeJS() { doupdate() }
        function closeJS2() { doupdate() }
        function doupdate() {
            var grid = ISGetObject("WebGrid1");
            grid.ClearSelectedObject();
            grid.RootTable.UpdateUI();
            grid.Refresh();

        }
        function popupattach1() {

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();



            //get the key value of selected row.
            var key = row.KeyValue;

            TINY.box.show({ iframe: 'neatupload.aspx?BDID=' + key, boxid: 'frameless', width: 540, height: 450, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS() } });




        }
        function popupattach2() {

            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();
            var key = row.KeyValue;

            //get the key value of selected row.
            TINY.box.show({ iframe: 'AttachmentListPopup.aspx?BDID=' + key, boxid: 'frameless', width: 350, height: 250, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS2() } })
        }
        function addclick() {
            var pytxt = document.getElementById('<%=PlanYearsTxt.ClientID%>').value
            var vstxt = document.getElementById('<%=VersionTxt.ClientID%>').value

            TINY.box.show({ iframe: 'AddNewP.aspx?FormID=P03&PlanYear=' + pytxt + '&Version=' + vstxt, boxid: 'frameless', width: 500, height: 200, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS() } });
        }
        function editclick(fctr, product) {
            var pytxt = document.getElementById('<%=PlanYearsTxt.ClientID%>').value
             var vstxt = document.getElementById('<%=VersionTxt.ClientID%>').value

             TINY.box.show({ iframe: 'P03_Edit.aspx?FormID=P03&PlanYear=' + pytxt + '&Version=' + vstxt + '&FCTR=' + fctr + '&Product=' + product, boxid: 'frameless', width: 1080, height: 600, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { closeJS() } });
         }
    </script>

    <script>
        function WebGrid1_OnAfterExitEditMode(controlId, tblName, editObject) {

            var WebGrid1 = ISGetObject(controlId);
            var rootTable = WebGrid1.RootTable;
            var cell = wgGetCellByElement(editObject.cellElement);
            var colName = cell.Name;

            var row = cell.Row;
            var htmlRow = row.GetElement();


            var cellsplit = cell.Value.toString().split(".");

            if (cellsplit[1] !== undefined && cellsplit[1].length > 2) {
                cell.SetText(cell.Text, true);
            }

            var cellval = 0;
            cellval = cell.Value;
            if (cellval + '' == "NaN" || cellval == 0) {
                cell.SetText("0.00", true);
            }



            //CalData();

        }
        var editCancel = 0;
        function WebGrid1_OnBeforeRowSelect(controlId, tblName, lastSelectedObject) {

            if (editCancel == 1) {
                //CalData();
            }
            editCancel = 0;
            return true;
        }
        function WebGrid1_OnCancelRowEditing(controlId, tblName, editObject) {
            editCancel = 1;

        }
        function CalData() {
            return;
            //alert("cal");
            var WebGrid1 = ISGetObject("WebGrid1");
            var rootTable = WebGrid1.RootTable;


            var curRow = WebGrid1.GetSelectedObject().rowIndex;
            //var row = grid.RootTable.GetRow(0);
            //var rowObj = grid.GetSelectedObject().GetRowObject();
            //var htmlRow = row.GetElement();
            // var num1 = parseFloat((wgGetCellByPosition(htmlRow, 2).innerText).replace(/\,/g, ''));
            //alert(curRow)
            //alert(wgGetCellByPosition(htmlRow, 2).innerText)
            var startRowIdex

            if (curRow <= 6) {
                startRowIdex = 0
            } else {

                startRowIdex = 7;
            }
            var row;
            var htmlRow;




            for (var nj = 5; nj <= 32; nj++) {

                if (nj != 10 && nj != 18 && nj != 19 && nj != 32) {
                    row = WebGrid1.RootTable.GetRow(startRowIdex);
                    htmlRow = row.GetElement();
                    var num1 = parseFloat((wgGetCellByPosition(htmlRow, nj).innerText).replace(/\,/g, ''));

                    row = WebGrid1.RootTable.GetRow(startRowIdex + 1);
                    htmlRow = row.GetElement();
                    var num2 = parseFloat((wgGetCellByPosition(htmlRow, nj).innerText).replace(/\,/g, ''));

                    row = WebGrid1.RootTable.GetRow(startRowIdex + 2);
                    htmlRow = row.GetElement();
                    var num3 = parseFloat((wgGetCellByPosition(htmlRow, nj).innerText).replace(/\,/g, ''));

                    row = WebGrid1.RootTable.GetRow(startRowIdex + 3);
                    htmlRow = row.GetElement();
                    var num4 = parseFloat((wgGetCellByPosition(htmlRow, nj).innerText).replace(/\,/g, ''));

                    var result = num1 + num2 + num3 + num4;
                    row = WebGrid1.RootTable.GetRow(startRowIdex + 4);
                    var rcell2 = row.GetCells();
                    result = result.toFixed(2);
                    if (nj + 2 < 22) {
                        rcell2[nj + 2].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);

                    }
                    else {
                        rcell2[nj + 4].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);

                    }

                    row = WebGrid1.RootTable.GetRow(startRowIdex + 5);
                    htmlRow = row.GetElement();
                    var num5 = parseFloat((wgGetCellByPosition(htmlRow, nj).innerText).replace(/\,/g, ''));
                    var result2;

                    if (num5 + '' == "NaN" || num5 == 0) {
                        result2 = 100;

                    }
                    else {
                        result2 = ((num1 + num2 + num3 + num4) * 100) / num5;
                        if (nj == 17) {
                        }
                    }
                    row = WebGrid1.RootTable.GetRow(startRowIdex + 6);


                    var rcell3 = row.GetCells();
                    result2 = result2.toFixed(2);
                    if (nj < 20) {
                        rcell3[nj + 2].SetText(String(result2).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                    }
                    else {
                        rcell3[nj + 4].SetText(String(result2).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                    }






                }
                else if (nj == 10) {

                    for (var iz = startRowIdex; iz <= startRowIdex + 6; iz++) {
                        if (iz != 5 && iz != 9) {
                            row = WebGrid1.RootTable.GetRow(iz);

                            htmlRow = row.GetElement();

                            var num1 = parseFloat((wgGetCellByPosition(htmlRow, 5).innerText).replace(/\,/g, ''));
                            var num2 = parseFloat((wgGetCellByPosition(htmlRow, 6).innerText).replace(/\,/g, ''));
                            var num3 = parseFloat((wgGetCellByPosition(htmlRow, 7).innerText).replace(/\,/g, ''));
                            var num4 = parseFloat((wgGetCellByPosition(htmlRow, 8).innerText).replace(/\,/g, ''));
                            var num5 = parseFloat((wgGetCellByPosition(htmlRow, 9).innerText).replace(/\,/g, ''));
                            var result = 0;
                            if (iz == startRowIdex + 6) {
                                result = (num1 + num2 + num3 + num4 + num5) / 5;
                            }
                            else {
                                result = (num1 + num2 + num3 + num4 + num5);
                            }
                            result = result.toFixed(2);
                            var rcell2 = row.GetCells()
                            row.GetCells().GetNamedItem("tobtanx11").SetForceNoEdit(false);
                            rcell2[12].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                            row.GetCells().GetNamedItem("tobtanx11").SetForceNoEdit(true);
                        }
                        else {
                            //alert(ix);
                            row = WebGrid1.RootTable.GetRow(iz);

                            htmlRow = row.GetElement();
                            var num7 = parseFloat((wgGetCellByPosition(htmlRow, 9).innerText).replace(/\,/g, ''));
                            var result = 0;
                            result = num7;
                            result = result.toFixed(2);
                            var rcell4 = row.GetCells()
                            row.GetCells().GetNamedItem("tobtanx11").SetForceNoEdit(false);
                            rcell4[12].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                            row.GetCells().GetNamedItem("tobtanx11").SetForceNoEdit(true);
                        }
                    }

                }
                else if (nj == 18) {

                    for (var ix = startRowIdex; ix <= startRowIdex + 6; ix++) {
                        if (ix != 5 && ix != 9) {
                            row = WebGrid1.RootTable.GetRow(ix);

                            htmlRow = row.GetElement();

                            var num1 = parseFloat((wgGetCellByPosition(htmlRow, 11).innerText).replace(/\,/g, ''));
                            var num2 = parseFloat((wgGetCellByPosition(htmlRow, 12).innerText).replace(/\,/g, ''));
                            var num3 = parseFloat((wgGetCellByPosition(htmlRow, 13).innerText).replace(/\,/g, ''));
                            var num4 = parseFloat((wgGetCellByPosition(htmlRow, 14).innerText).replace(/\,/g, ''));
                            var num5 = parseFloat((wgGetCellByPosition(htmlRow, 15).innerText).replace(/\,/g, ''));
                            var num6 = parseFloat((wgGetCellByPosition(htmlRow, 16).innerText).replace(/\,/g, ''));
                            var num7 = parseFloat((wgGetCellByPosition(htmlRow, 17).innerText).replace(/\,/g, ''));
                            var result = 0;
                            if (ix == startRowIdex + 6) {
                                result = (num1 + num2 + num3 + num4 + num5 + num6 + num7) / 7;
                            }
                            else {
                                result = (num1 + num2 + num3 + num4 + num5 + num6 + num7);
                            }
                            result = result.toFixed(2);
                            var rcell2 = row.GetCells()
                            row.GetCells().GetNamedItem("trueyX1").SetForceNoEdit(false);
                            rcell2[20].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                            row.GetCells().GetNamedItem("trueyX1").SetForceNoEdit(true);
                        }
                        else {
                            //alert(ix);
                            row = WebGrid1.RootTable.GetRow(ix);

                            htmlRow = row.GetElement();
                            var num7 = parseFloat((wgGetCellByPosition(htmlRow, 17).innerText).replace(/\,/g, ''));
                            var result = 0;
                            result = num7;
                            result = result.toFixed(2);
                            var rcell4 = row.GetCells()
                            row.GetCells().GetNamedItem("trueyX1").SetForceNoEdit(false);
                            rcell4[20].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                            row.GetCells().GetNamedItem("trueyX1").SetForceNoEdit(true);
                        }

                    }

                }
                else if (nj == 19) {

                    for (var ixx = startRowIdex; ixx <= startRowIdex + 6; ixx++) {
                        if (ixx != 5 && ixx != 9) {
                            row = WebGrid1.RootTable.GetRow(ixx);

                            htmlRow = row.GetElement();
                            var num1 = parseFloat((wgGetCellByPosition(htmlRow, 5).innerText).replace(/\,/g, ''));
                            var num2 = parseFloat((wgGetCellByPosition(htmlRow, 6).innerText).replace(/\,/g, ''));
                            var num3 = parseFloat((wgGetCellByPosition(htmlRow, 7).innerText).replace(/\,/g, ''));
                            var num4 = parseFloat((wgGetCellByPosition(htmlRow, 8).innerText).replace(/\,/g, ''));
                            var num5 = parseFloat((wgGetCellByPosition(htmlRow, 9).innerText).replace(/\,/g, ''));
                            var num6 = parseFloat((wgGetCellByPosition(htmlRow, 11).innerText).replace(/\,/g, ''));
                            var num7 = parseFloat((wgGetCellByPosition(htmlRow, 12).innerText).replace(/\,/g, ''));
                            var num8 = parseFloat((wgGetCellByPosition(htmlRow, 13).innerText).replace(/\,/g, ''));
                            var num9 = parseFloat((wgGetCellByPosition(htmlRow, 14).innerText).replace(/\,/g, ''));
                            var num10 = parseFloat((wgGetCellByPosition(htmlRow, 15).innerText).replace(/\,/g, ''));
                            var num11 = parseFloat((wgGetCellByPosition(htmlRow, 16).innerText).replace(/\,/g, ''));
                            var num12 = parseFloat((wgGetCellByPosition(htmlRow, 17).innerText).replace(/\,/g, ''));
                            var result = 0;
                            if (ixx == startRowIdex + 6) {
                                result = (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10 + num11 + num12) / 12;
                            }
                            else {
                                result = (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10 + num11 + num12);
                            }
                            result = result.toFixed(2);
                            var rcell2 = row.GetCells()
                            row.GetCells().GetNamedItem("trueyX2").SetForceNoEdit(false);
                            rcell2[21].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                            row.GetCells().GetNamedItem("trueyX2").SetForceNoEdit(true);
                        }
                        else {
                            row = WebGrid1.RootTable.GetRow(ixx);

                            htmlRow = row.GetElement();
                            var num7 = parseFloat((wgGetCellByPosition(htmlRow, 17).innerText).replace(/\,/g, ''));
                            var result = 0;
                            result = num7;
                            result = result.toFixed(2);
                            var rcell2 = row.GetCells()
                            row.GetCells().GetNamedItem("trueyX2").SetForceNoEdit(false);
                            rcell2[21].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                            row.GetCells().GetNamedItem("trueyX2").SetForceNoEdit(true);
                        }
                    }
                }
                else if (nj == 32) {

                    for (var ixxx = startRowIdex; ixxx <= startRowIdex + 6; ixxx++) {
                        if (ixxx != 5 && ixxx != 9) {
                            row = WebGrid1.RootTable.GetRow(ixxx);

                            htmlRow = row.GetElement();
                            var num1 = parseFloat((wgGetCellByPosition(htmlRow, 20).innerText).replace(/\,/g, ''));
                            var num2 = parseFloat((wgGetCellByPosition(htmlRow, 21).innerText).replace(/\,/g, ''));
                            var num3 = parseFloat((wgGetCellByPosition(htmlRow, 22).innerText).replace(/\,/g, ''));
                            var num4 = parseFloat((wgGetCellByPosition(htmlRow, 23).innerText).replace(/\,/g, ''));
                            var num5 = parseFloat((wgGetCellByPosition(htmlRow, 24).innerText).replace(/\,/g, ''));
                            var num6 = parseFloat((wgGetCellByPosition(htmlRow, 25).innerText).replace(/\,/g, ''));
                            var num7 = parseFloat((wgGetCellByPosition(htmlRow, 26).innerText).replace(/\,/g, ''));
                            var num8 = parseFloat((wgGetCellByPosition(htmlRow, 27).innerText).replace(/\,/g, ''));
                            var num9 = parseFloat((wgGetCellByPosition(htmlRow, 28).innerText).replace(/\,/g, ''));
                            var num10 = parseFloat((wgGetCellByPosition(htmlRow, 29).innerText).replace(/\,/g, ''));
                            var num11 = parseFloat((wgGetCellByPosition(htmlRow, 30).innerText).replace(/\,/g, ''));
                            var num12 = parseFloat((wgGetCellByPosition(htmlRow, 31).innerText).replace(/\,/g, ''));

                            var result = 0;
                            if (ixxx == startRowIdex + 6) {
                                result = (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10 + num11 + num12) / 12;
                            } else {
                                result = (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10 + num11 + num12);
                            }
                            result = result.toFixed(2);
                            var rcell2 = row.GetCells()
                            row.GetCells().GetNamedItem("trueyX23").SetForceNoEdit(false);
                            rcell2[36].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                            row.GetCells().GetNamedItem("trueyX23").SetForceNoEdit(true);
                        }
                        else {
                            row = WebGrid1.RootTable.GetRow(ixxx);

                            htmlRow = row.GetElement();
                            var num11 = parseFloat((wgGetCellByPosition(htmlRow, 31).innerText).replace(/\,/g, ''));
                            var result = 0;
                            result = num11;
                            result = result.toFixed(2);
                            var rcell2 = row.GetCells()
                            row.GetCells().GetNamedItem("trueyX23").SetForceNoEdit(false);
                            rcell2[36].SetText(String(result).replace(/\B(?=(\d{3})+(?!\d))/g, ","), true);
                            row.GetCells().GetNamedItem("trueyX23").SetForceNoEdit(true);
                        }
                    }
                }
            }



        }
        function WebGrid1_OnRowContextMenu(controlId, rowType, rowElement, menuObject) {
            menuObject.Items[0].Hide();

            return false;
        }
        function FundCenterCombo_OnAfterItemSelected(controlId) {


            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();

            var cells = row.GetCells();




            var code_combo = ISGetObject("ProductCombo");
            code_combo.ClearSelection();
            code_combo.Value = "";
            code_combo.SetTextBoxValue("");
            row.GetCells().GetNamedItem("Product").SetText("", true);

            var code_combo22 = ISGetObject("PitemTCombo");
            code_combo22.ClearSelection();
            code_combo22.Value = "";
            code_combo22.SetTextBoxValue("");
            row.GetCells().GetNamedItem("ProitemId").SetText("", true);


        }

        function OnRowSelect(controlId, tblName, rowIndex, rowElm) {


            var grid = ISGetObject("WebGrid1");
            var row = grid.GetSelectedObject().GetRowObject();
            var ar = grid.GetSelectedObject().GetRowElement();

            if (ar.IsAddNewRow == false) {
                                       
                var combo = ISGetObject("FundCenterCombo");
                var Val = row.GetCells().GetNamedItem("FundCenter").Value

                combo.SetValue(Val);
            }

        }
        function WebGrid1_OnRowValidate(rowObject) {

            //var grid = ISGetObject("WebGrid1");

            //// access WebGrid's RootTable
            //var rootTable = grid.RootTable;

            //var row = rootTable.ToRowObject(rowObject); // convert the rowObject (HTMLElement) to WebGridRow object
            //var htmlRow = row.GetElement();
            //var cells = row.GetCells(); // get collection of WebGridCell
            var error = 0;
            //var err_text = " \n"

            ////alert("1");
            //var data
            //var num;
            //for (var nj = 11; nj <= 32; nj++) {
            //    num = parseFloat((wgGetCellByPosition(htmlRow, nj).innerText).replace(/\,/g, ''));
            //    if (num < 0) {
            //        err_text = "กรุณาตรวจสอบจำนวนเงิน";
            //        error = error + 1;
            //    }
            //}

            //alert("2");
            if (error == 0) {
                CustomRequestUpdate();
                return true;
            } else {
                //alert(err_text);
                //CalData();
                return false;
            }

        }

        function WebGrid1_OnEditKeyDown(controlId) {
            //alert(event.keyCode);
            var grid = ISGetObject("WebGrid1");

            var totalRows = grid.TotalRows;
            var totalCells = grid.TotalCells;
            var curRow = grid.GetSelectedObject().rowIndex;
            var curCell = grid.GetActiveEditCell().cellIndex;

            // if enter key
            if (event.keyCode == 13) {
                if (totalRows >= 2) {
                    if (curRow < totalRows - 1) {
                        keyDown(curRow, curRow + 1, curCell - 1);
                    }
                }
                //grid.ExitEdit(1,0,0);
                //return false;
                //var ar = grid.GetSelectedObject().GetRowElement();

                //if (ar.IsAddNewRow) {
                //    ar.commit();
                //}
                //else {
                //    event.keyCode = 40;
                //    keyDown(curRow, curRow + 1, curCell - 1);
                //}
            }

                // if up arrow
            else if (event.keyCode == 38 && grid.GetSelectedObject().GetRowObject().Type != "NewRow") {
                if (totalRows >= 2) {
                    if (curRow > 0) {
                        keyDown(curRow, curRow - 1, curCell - 1);
                    }
                }
            }

                // if down arrow key
            else if (event.keyCode == 40 && grid.GetSelectedObject().GetRowObject().Type != "NewRow") {
                if (totalRows >= 2) {
                    if (curRow < totalRows - 1) {
                        keyDown(curRow, curRow + 1, curCell - 1);
                    }
                }
            }
                // if left arrow key
            else if (event.keyCode == 37) {

                if (curCell > 1) {
                    //jq(document).trigger(jq.Event('keydown', { keyCode: 9, shiftKey: true }));
                    //var press = jQuery.Event("keydown");
                    //press.shiftKey = false;
                    //press.which = 9;
                    //jq("WebGrid1").trigger(press);
                    //alert("x");
                    //return;
                    keyDown2(curRow, curCell - 2);

                }
            }
                // if right arrow key
            else if (event.keyCode == 39) {
                //if (curCell < totalCells - 1) {
                event.keyCode = 9;
                return true;
                //}
            }


        }

        function keyDown(curRow, nextRow, cell) {
            var grid = ISGetObject("WebGrid1");
            var nextRowEl = grid.RootTable.GetRow(nextRow);
            var curRowEl = grid.RootTable.GetRow(curRow);
            var cell1 = nextRowEl.GetCell(cell);
            var cell2 = curRowEl.GetCell(cell);
            grid.ExitEdit(1, 0, 0);
            grid.SetFocus();

            cell2.Select(true);

            nextRowEl.Select();

            cell1.ActivateEdit();
        }
        function keyDown2(curRow, cell) {
            var grid = ISGetObject("WebGrid1");

            var selectedObject = grid.GetSelectedObject(); // return object of type SelectedObject
            var selectedRow = selectedObject.ToRowObject();
            var cell1 = selectedRow.GetCell(cell);
            grid.SetFocus();
            cell1.Select(true);
            cell1.ActivateEdit();

        }

        function triggerKeyEvents(field, keyCode, shiftKey, ctrlKey) {

            field = $(field);

            shiftKey = Boolean(shiftKey);

            ctrlKey = Boolean(ctrlKey);


            field.simulate("keydown", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

            field.simulate("keypress", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });


            if (field.is(HTML5_TEXT_INPUT_FIELD_SELECTOR)) {

                applyKeyCodeToValue(field, keyCode);

            }


            field.simulate("keyup", {
                keyCode: keyCode,

                ctrlKey: ctrlKey,

                shiftKey: shiftKey
            });

        }

        function SaveScrollPosition(gridId, action) {
            // collecting the last position
            // of the vertical scrollbar
            // by obtaining the scrollTop property
            var grid = ISGetObject(gridId);
            // obtain the scrollTop and scrollLeft property 
            // of the vertical scrollbar and horizontal scrollbar
            var vl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop + "";
            var hl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft + "";
            // only send the scrollTop property
            // of the server if the action performed
            // by the grid OTFPB is 'Refresh'

            //if (action == "Refresh") {
            // sending over the scrollTop and scrollLeft property
            // to the server by using AddInput method
            grid.AddInput("scrollTopPos", vl);
            grid.AddInput("scrollLeftPos", hl);
            //}

            return true;
        }

        function ApplyLatestScroll(gridId, y, x) {
            // set back the previous scrollTop and scrollLeft property or
            // vertical and horizontal scroll position with 
            // the parameter sent from the server side
            var grid = ISGetObject(gridId);
            // manually configure the vertical and horizontal scroll position
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop = y;
            grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft = x;

            var cellEl = grid.GetActiveEditCell().ToCellObject();
            grid.SetFocus();
            cellEl.ActivateEdit();
            return true;
        }

        function CustomRequestDel() {
            if (confirm('กรุณายืนยันการลบข้อมูล') == false) {
                return false
            }
            var grid = ISGetObject("WebGrid1");
            var table = grid.GetRootTable();
            var checkedRows = table.GetCheckedRows();

            if (checkedRows.length == 0) {
                alert("Please check an item.");
                setTimeout(function () { grid.SetFocus(); }, 10);
            }
            else {

                grid.AddInput("type", "2");
                grid.SendCustomRequest();

            }

            event.cancelBubble = true;
            event.returnValue = false;
        }

        function CustomRequestCopy() {
            if (confirm('กรุณายืนยันการคัดลอกข้อมูล') == false) {
                return false
            }
            var grid = ISGetObject("WebGrid1");
            var table = grid.GetRootTable();
            var checkedRows = table.GetCheckedRows();

            if (checkedRows.length == 0) {
                alert("Please check an item.");
                setTimeout(function () { grid.SetFocus(); }, 10);
            }
            else {

                grid.AddInput("type", "1");
                grid.SendCustomRequest();

            }

            event.cancelBubble = true;
            event.returnValue = false;
        }

        function CustomRequestUpdate() {
            var grid = ISGetObject("WebGrid1");
            var row;
            var htmlRow;
            var curRow = grid.GetSelectedObject().rowIndex;
            var startRowIdex

            if (curRow <= 6) {
                startRowIdex = 0
            } else {

                startRowIdex = 7;
            }

            var row1 = "";
            var row2 = "";
            var row3 = "";
            var row4 = "";
            var row5 = "";
            var row6 = "";
            var row7 = "";

            var obj;
            var rowobj;
            var key;

            for (var f = 0; f <= 6; f++) {
                row = grid.RootTable.GetRow(startRowIdex + f);
                htmlRow = row.GetElement();
                key = row.KeyValue;
                if (f == 0) {
                    row1 += key + ";"
                }
                else if (f == 1) {
                    row2 += key + ";"
                }
                else if (f == 2) {
                    row3 += key + ";"
                }
                else if (f == 3) {
                    row4 += key + ";"
                }
                else if (f == 4) {
                    row5 += key + ";"
                }
                else if (f == 5) {
                    row6 += key + ";"
                }
                else if (f == 6) {
                    row7 += key + ";"
                }
                for (var n1 = 4; n1 <= 32; n1++) {


                    if (f == 0) {
                        row1 += parseFloat((wgGetCellByPosition(htmlRow, n1).innerText).replace(/\,/g, '')) + ";";
                    }
                    else if (f == 1) {
                        row2 += parseFloat((wgGetCellByPosition(htmlRow, n1).innerText).replace(/\,/g, '')) + ";";
                    }
                    else if (f == 2) {
                        row3 += parseFloat((wgGetCellByPosition(htmlRow, n1).innerText).replace(/\,/g, '')) + ";";
                    }
                    else if (f == 3) {
                        row4 += parseFloat((wgGetCellByPosition(htmlRow, n1).innerText).replace(/\,/g, '')) + ";";
                    }
                    else if (f == 4) {
                        row5 += parseFloat((wgGetCellByPosition(htmlRow, n1).innerText).replace(/\,/g, '')) + ";";
                    }
                    else if (f == 5) {
                        row6 += parseFloat((wgGetCellByPosition(htmlRow, n1).innerText).replace(/\,/g, '')) + ";";
                    }
                    else if (f == 6) {
                        row7 += parseFloat((wgGetCellByPosition(htmlRow, n1).innerText).replace(/\,/g, '')) + ";";
                    }

                }
            }



            grid.AddInput("type", "3");
            grid.AddInput("kval", key);
            grid.AddInput("row1", row1);
            grid.AddInput("row2", row2);
            grid.AddInput("row3", row3);
            grid.AddInput("row4", row4);
            grid.AddInput("row5", row5);
            grid.AddInput("row6", row6);
            grid.AddInput("row7", row7);

            grid.SendCustomRequest();

            event.cancelBubble = true;
            event.returnValue = false;
        }

        // This function is invoked when the custom request is about to be made.
        function wgPrepareCustomAction(grid, xmlr, name) {
            grid.SetStatus1("Processing...");
            return true;
        }
        var exp = '0';
        function WebTreeView3_Expand() {
            exp = '1';
            var combo = ISGetObject("WebCombo3");
            combo.SetFocus();
            combo.ShowDropDown();
        }
        function WebTreeView3_Collapse() {
            exp = '1';
            var combo = ISGetObject("WebCombo3");
            combo.SetFocus();
            combo.ShowDropDown();
        }
        function WebCombo3_Hide() {
            if (exp == '1') {
                exp = '0';
                var combo = ISGetObject("WebCombo3");
                combo.SetFocus();
                combo.ShowDropDown();
            }
        }

        function WebGrid1_OnEnterEditMode(controlId, tblName, editObject) {

        }


        function saveclick() {
            var grid = ISGetObject("WebGrid1");
            grid.ExitEdit(1, 0, 0);
            //CalData();
            CustomRequestUpdate();
        }

        function SetFooter(cellNo, cellValue) {
            var WebGrid1 = ISGetObject("WebGrid1");
            var colFooterCell = WebGrid1.RootTable.GetElement(WG40.COLFOOTER, WG40.HTMLTABLE).cells[cellNo];

            var strval = cellValue.toFixed(2).toString();
            strval = strval.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
            colFooterCell.innerText = strval;
        }
    </script>
    <style>
        .WC4-DD-N {
            height: 0px;
        }

        .WC4-DD-A {
            height: 0px;
        }
    </style>
    <style type="text/css">
        .tbox {
            z-index: 10000;
        }
    </style>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="margin-left: 10px; padding: 10px 10px 10px 10px;">
        <div style="float: left; width: 97%; border: solid; border-color: gray; border-width: 1px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; text-align: right; padding: 5px 5px 5px 5px;">
            <div style="text-align: right; margin-top: 5px;">
                <div align="left" style="width: 600px; float: left">
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </div>

                ปี&nbsp;
            <asp:TextBox ID="PlanYearsTxt" runat="server" Width="50px" Enabled="false" Style="text-align: center;"></asp:TextBox>
                &nbsp;&nbsp;&nbsp;&nbsp;
            Version&nbsp;
                <asp:TextBox ID="VersionTxt" runat="server" Width="30px" Enabled="false" Style="text-align: center"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" title="เลือกหน่วยงานและโครงการที่ต้องการ จากนั้นคลิกที่ปุ่มนี้เพื่อทำการค้นหา">
                <asp:ImageButton ID="SearhBtn" runat="server" ImageUrl="Icons/search.jpg" OnClientClick="clickedx()" /></a>
                &nbsp;&nbsp;<asp:ImageButton ID="AddBtn" runat="server" ImageUrl="Icons/add.png" OnClientClick="addclick(); return false;" />
                &nbsp;&nbsp;<a href="#" title="เลือกรายการที่ต้องการ จากนั้นคลิกปุ่มนี้เพิ่อทำการลบรายการ"><asp:ImageButton ID="delete_btn" runat="server" ImageUrl="Icons/delete.jpg" OnClientClick="CustomRequestDel(); return false" /></a>
                &nbsp;&nbsp;<asp:ImageButton ID="SaveBtn" runat="server" ImageUrl="Icons/save.jpg" Style="height: 21px" OnClientClick="saveclick(); return false;" Visible="false" />
                &nbsp;
            </div>
        </div>
        <div>
            <div id="div1" runat="server" style="float: left; width: 40%; border: solid; border-color: gray; border-width: 1px; margin-right: 10px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; height: 92px;">

                <div style="padding-bottom: 5px;"><strong>&nbsp;FundCenter</strong></div>


                <asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="1" Height="30px" Width="100%" EnableTheming="True">
                    <asp:TabPanel ID="TabPanel1" runat="server" HeaderText="ตั้งแต่ ถึง">
                        <ContentTemplate>
                            <table>
                                <tr>
                                    <td>ตั้งแต่</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo1" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" AdditionalSearchFields="FundCenterCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>
                                        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByUser" TypeName="BasicDataTableAdapters.FCTR_Child2TableAdapter">
                                            <SelectParameters>
                                                <asp:SessionParameter Name="username" SessionField="users" Type="String" />
                                            </SelectParameters>
                                        </asp:ObjectDataSource>
                                    </td>
                                    <td>ถึง</td>
                                    <td>
                                        <ISWebCombo:WebCombo ID="WebCombo2" Width="200px" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" AdditionalSearchFields="FundCenterCode" AllowWildCardSearch="true">
                                            <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" ComboMode="MultipleColumns">
                                            </LayoutSettings>
                                            <Columns>
                                                <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                                                <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                                            </Columns>
                                        </ISWebCombo:WebCombo>
                                        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByUser" TypeName="BasicDataTableAdapters.FCTR_Child2TableAdapter">
                                            <SelectParameters>
                                                <asp:SessionParameter Name="username" SessionField="users" Type="String" />
                                            </SelectParameters>
                                        </asp:ObjectDataSource>
                                    </td>
                                </tr>
                            </table>

                        </ContentTemplate>
                    </asp:TabPanel>
                    <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="เลือกเอง">
                        <ContentTemplate>
                            <div style="margin-left: 30px; color: gray; font-size: 11px;">
                                <ISWebCombo:WebCombo ID="WebCombo3" runat="server" UseDefaultStyle="True" Width="350px" DataTextField="pathname" DataValueField="Fundcenter_FundcenterCode" AllowWildCardSearch="true" DropDownRows="100000">
                                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false">
                                    </LayoutSettings>                                    
                                </ISWebCombo:WebCombo>
                                &nbsp;(รวมหน่วยงานใต้สังกัด)
                            </div>
                        </ContentTemplate>
                    </asp:TabPanel>
                </asp:TabContainer>
            </div>
            <div id="div2" runat="server" style="float: right; width: 55%; border: solid; border-color: gray; border-width: 1px; margin-right: 30px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; height: 92px;">
                &nbsp;
                <strong>ผลิตภัณฑ์ </strong>

                <div style="margin: 5px 5px 5px 5px;">
                    <asp:HiddenField runat="server" ID="hdf1" />
                    <asp:ListBox ID="ms8" runat="server" Width="97%" SelectionMode="Multiple"></asp:ListBox><br />
                </div>
                <script type="text/javascript">
                    $(document).ready(function () {

                        var ms7 = $('#<%= ms8.ClientID%>').magicSuggest({
                            // will fetch data from options
                        });

                        clickedx = function () {

                            $("#<%= hdf1.ClientId %>").val(ms7.getValue());
                        }
                    });
                </script>
            </div>
            <div style="float: left; width: 97%; border: solid; border-color: gray; border-width: 1px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px;">

                <div style="padding-bottom: 5px;"><strong>เป้าหมาย NPL</strong></div>


                <ISWebGrid:WebGrid ID="WebGrid1" runat="server" UseDefaultStyle="True" Width="100%" DefaultStyleMode="Silver" Height="360px" OnInitializeRow="WebGrid1_InitializeRow" OnCustomAggregate="WebGrid1_CustomAggregate" OnInitializePostBack="WebGrid1_InitializePostBack">
                    <LayoutSettings AllowAddNew="No"  AllowColumnMove="No"
                        AllowDelete="No" AllowSorting="No" ColumnFooters="Yes"
                        InProgressUIBehavior="ChangeCursorToHourGlass"
                        AlwaysShowHelpButton="false" PagingMode="ClassicPaging" PagingSize="14"
                        AllowGrouping="Yes" AllowColumnFreezing="Yes" AllowColumnSizing="No">
                        <FreezePaneSettings ActiveFrozenColumns="5" MaxFrozenColumns="5" />
                        <RowStyle Font-Names="Tahoma" Font-Size="9" CustomRules="overflow: hidden;" />
                        <AlternatingRowStyle Font-Names="Tahoma" Font-Size="9" BackColor="#fbfbfb" CustomRules="overflow: hidden;" />
                        <ClientSideEvents OnRowValidate="WebGrid1_OnRowValidate" OnRowContextMenu="WebGrid1_OnRowContextMenu" OnRowSelect="OnRowSelect" OnEditKeyDown="WebGrid1_OnEditKeyDown" OnExitEditMode="WebGrid1_OnExitEditMode" OnAfterResponseProcess="DisableCheck" />
                    </LayoutSettings>
                    <RootTable DataKeyField="Id" NewRowInfoText="เพิ่มรายการ" RowLayout="ColumnSet" ColumnFooters="No">
                        <Columns>
                            <ISWebGrid:WebGridColumn IsRowChecker="true" Name="checker">
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Caption=" " ColumnType="Template" Name="Edit" Width="30px">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Center" />
                                <CellTemplate>
                                    <a href="#" style="text-decoration: none; border: none;" onclick='editclick("<%# Eval("FundCenter_FundCenterCode")%>","<%# Eval("ProductCode")%>")'>
                                        <img src="Icons/document_edit.png" height="16px" style="text-decoration: none; border: none;" />
                                    </a>
                                </CellTemplate>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Caption="Fund Center" Name="FundCenter" Width="100px" DataMember="FundCenter_FundCenterCode" EditType="WebComboNET" WebComboID="FundCenterCombo">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                                <ValueList DataTextField="Description" DataSourceID="FundCenterDataSource"
                                    DataValueField="FundCenter_FundCenterCode">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>

                            <ISWebGrid:WebGridColumn Name="Product" Width="140px" Caption="ผลิตภัณฑ์" DataMember="ProductCode" EditType="WebComboNET" WebComboID="ProductCombo">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                                <ValueList DataTextField="ProductDesc" DataSourceID="ProductDataSource"
                                    DataValueField="ProductCode">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="ProitemId" Width="140px" Caption="รายการย่อย" DataMember="ProItemDesc" FooterText="รวมทั้งหมด">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Left" />
                                <ValueList DataTextField="ProItemDesc"
                                    DataValueField="ProductItem_ID">
                                </ValueList>
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="result1" Width="140px" Caption="ผลจริงปี" DataMember="ActualLastYear2" DataFormatString="##,##0.00" AggregateFunction="Custom" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey1" Width="140px" Caption="ม.ค." DataMember="LastYearMonth1" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#FFB273"   BackColor2="#FFB273" />
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey2" Width="140px" Caption="ก.พ." DataMember="LastYearMonth2" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#FFB273"   BackColor2="#FFB273"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey3" Width="140px" Caption="มี.ค." DataMember="LastYearMonth3" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#FFB273"   BackColor2="#FFB273"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey4" Width="140px" Caption="เม.ย." DataMember="LastYearMonth4" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#FFB273"   BackColor2="#FFB273"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey5" Width="140px" Caption="พ.ค." DataMember="LastYearMonth5" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#FFB273"   BackColor2="#FFB273"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="tobtanx11" Width="140px" Caption="รวม" DataMember="ActualLastYear1" DataFormatString="##,##0.00" AggregateFunction="Custom" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#FFB273"   BackColor2="#FFB273"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey6" Width="140px" Caption="มิ.ย." DataMember="LastYearMonth6" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#5CCCCC"   BackColor2="#5CCCCC"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>

                            <ISWebGrid:WebGridColumn Name="truey7" Width="140px" Caption="ก.ค." DataMember="LastYearMonth7" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#5CCCCC"   BackColor2="#5CCCCC"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey8" Width="140px" Caption="ส.ค." DataMember="LastYearMonth8" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#5CCCCC"   BackColor2="#5CCCCC"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey9" Width="140px" Caption="ก.ย." DataMember="LastYearMonth9" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#5CCCCC"   BackColor2="#5CCCCC"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey10" Width="140px" Caption="ต.ค." DataMember="LastYearMonth10" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#5CCCCC"   BackColor2="#5CCCCC"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey11" Width="140px" Caption="พ.ย." DataMember="LastYearMonth11" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#5CCCCC"   BackColor2="#5CCCCC"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey12" Width="140px" Caption="ธ.ค." DataMember="LastYearMonth12" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#5CCCCC"   BackColor2="#5CCCCC"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="trueyX1" Width="140px" Caption="รวม" DataMember="ForecastLastYear1" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#5CCCCC"   BackColor2="#5CCCCC"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="trueyX2" Width="140px" Caption="รวมปีx" DataMember="SumFX" AggregateFunction="Custom" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" />
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey121" Width="140px" Caption="ม.ค." DataMember="CurYearMonth1" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey22" Width="140px" Caption="ก.พ." DataMember="CurYearMonth2" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey32" Width="140px" Caption="มี.ค." DataMember="CurYearMonth3" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey42" Width="140px" Caption="เม.ย." DataMember="CurYearMonth4" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey52" Width="140px" Caption="พ.ค." DataMember="CurYearMonth5" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey62" Width="140px" Caption="มิ.ย." DataMember="CurYearMonth6" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey72" Width="140px" Caption="ก.ค." DataMember="CurYearMonth7" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey82" Width="140px" Caption="ส.ค." DataMember="CurYearMonth8" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey92" Width="140px" Caption="ก.ย." DataMember="CurYearMonth9" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey102" Width="140px" Caption="ต.ค." DataMember="CurYearMonth10" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey112" Width="140px" Caption="พ.ย." DataMember="CurYearMonth11" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="truey122" Width="140px" Caption="ธ.ค." DataMember="CurYearMonth12" DataFormatString="##,##0.00" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Name="trueyX23" Width="140px" Caption="รวม" DataMember="ForecastCurYear" DataFormatString="##,##0.00" AggregateFunction="Custom" DefaultValue="0.00" DefaultText="0.00">
                                <HeaderStyle HorizontalAlign="Center" BackColor="#67E667"   BackColor2="#67E667"/>
                                <CellStyle HorizontalAlign="Right" />

                            </ISWebGrid:WebGridColumn>
                        </Columns>

                        <ColumnSetSettings ShowHeaders="Yes" RowCount="1" />

                    </RootTable>
                </ISWebGrid:WebGrid>
                <ISWebCombo:WebCombo ID="FundCenterCombo" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" Width="200px">
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false">
                        <ClientSideEvents OnAfterItemSelected="FundCenterCombo_OnAfterItemSelected" />
                    </LayoutSettings>
                </ISWebCombo:WebCombo>
                <ISWebCombo:WebCombo ID="ProductCombo" runat="server" UseDefaultStyle="true" DataTextField="ProductDesc" DataValueField="ProductCode">
                    <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false">
                    </LayoutSettings>
                </ISWebCombo:WebCombo>


            </div>
        </div>
    </div>
    <br />
    <br />
    <ISWebTreeView:WebTreeView ID="WebTreeView1" runat="server" Height="265px" Width="235px" Visible="false">
        <NodeSettings EnableAnimation="True" />
    </ISWebTreeView:WebTreeView>
    <ISWebTreeView:WebTreeView ID="WebTreeView2" runat="server" Height="265px" Width="235px" Visible="false">
        <NodeSettings EnableAnimation="True" />
    </ISWebTreeView:WebTreeView>
    <ISWebTreeView:WebTreeView ID="WebTreeView3" runat="server" Height="265px" Width="235px" Visible="false">
        <NodeSettings EnableAnimation="True" />

    </ISWebTreeView:WebTreeView>
    <asp:ObjectDataSource ID="FundCenterDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="BasicDataTableAdapters.FCTR_ValueTableAdapter">
        <SelectParameters>
            <asp:SessionParameter Name="PlanYear" SessionField="PlanYear" Type="Int16" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="ProductDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByPlanYear" TypeName="MSinchuaTableAdapters.Products1TableAdapter" DeleteMethod="Delete" UpdateMethod="Update">
        <DeleteParameters>
            <asp:Parameter Name="ProductCode" Type="Int32" />
        </DeleteParameters>
        <SelectParameters>
            <asp:SessionParameter Name="PY" SessionField="PlanYear" Type="Int16" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="ProductDesc" Type="String" />
            <asp:Parameter Name="ProductCode" Type="Int32" />
        </UpdateParameters>
    </asp:ObjectDataSource>

    <script>
        function WebGrid_GetTotalRowCount() {

            try {

                var grid = ISGetObject("WebGrid1")
                if (grid == null || grid.RootTable == null) { alert(grid); return 0; }

                // NOTE: This is done because Intersoft doesn't return the TotalRows accurately for a WebGrid using BatchUpdate
                var rowCount = 0;
                while (true) {
                    var row = grid.RootTable.GetRow(rowCount)
                    if (row == null) { return rowCount; }
                    rowCount++;
                }
                //alert(rowCount);
            }
            catch (ex) {
                ShowJSException(ex);

            }
        }

        function DisableCheck() {
            try{
            var rowcount = WebGrid_GetTotalRowCount();
            var WebGrid1 = ISGetObject("WebGrid1");
            var rowCheckerElm = WebGrid1.RootTable.GetElement(WG40.COLHEADER, WG40.HTMLTABLE).cells[1].childNodes[0].childNodes[0].childNodes[0];

            if (rowcount == 0) {
                rowCheckerElm.checked = false;
                rowCheckerElm.disabled = true;


                return true;
            } else {
                rowCheckerElm.disabled = false;

            }
            } catch (err) { }
        }
        DisableCheck();
    </script>

</asp:Content>
